package test;

import java.util.ArrayList;
import java.util.List;

/**
 * 顾客
 */
public class Customer {
    /**
     * 姓名
     */
    private String name;

    /**
     * 租赁集合
     */
    private List<Rental> rentals = new ArrayList<>();

    public Customer(String name) {
        this.name = name;
    }

    public void addRental(Rental rental) {
        this.rentals.add(rental);
    }

    public String getName() {
        return name;
    }

    /**
     * 获取租赁信息及费用一览表
     */
    public String statement() {
        // 总费用
        double totalAmount = 0.0;
        // 积分
        int renderPoint = 0;
        String result = "【" + this.name + "】的租赁记录：\n";
        for (Rental rental : this.rentals) {
            // 单条费用
            double thisAmount = 0.0;
            switch (rental.getMovie().getPriceCode()) {
                case Movie.CODE_REGULAR:
                    // 两天内的普通影片2块钱
                    thisAmount += 2;
                    if (rental.getDays() > 2) {
                        // 超过2两天的每天加收1.5元
                        thisAmount += (rental.getDays() - 2) * 1.5;
                    }
                    break;
                case Movie.CODE_NEW:
                    // 新片每天3元
                    thisAmount += rental.getDays() * 3;
                    break;
                case Movie.CODE_CHILDRENS:
                    // 两天内的儿童片1块钱
                    thisAmount += 1;
                    if (rental.getDays() > 2) {
                        // 超过2两天的每天加收1元
                        thisAmount += (rental.getDays() - 2) * 1;
                    }
                    break;
            }
            // 积分加一
            renderPoint++;
            // 如果是新片并且租期大于1天，积分翻倍
            if (rental.getMovie().getPriceCode() == Movie.CODE_NEW && rental.getDays() > 1) {
                renderPoint++;
            }
            result += "\t" + rental.getMovie().getTitle() + "\t" + thisAmount + "\n";
            totalAmount += thisAmount;
        }
        result += "总费用是：【" + totalAmount + "】\n";
        result += "你挣了：【" + renderPoint + "】积分\n";
        return result;
    }
}
